package com.myccb.app.view.investment;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.myccb.app.R;

import java.util.ArrayList;

/**
 * Created by freak on 17-12-6.
 */

class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
    Context mContext;

    CustomAdapter(Context context){
        mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.recyclerview_investment_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.getTextView(0).setText(DataSet.BENE_PERC[position]);
        holder.getTextView(1).setText(DataSet.BENE_DESCR[position]);
        holder.getTextView(2).setText(DataSet.TITLES[position]);
        holder.getTextView(3).setText(DataSet.LIMITS[position]);
        holder.getTextView(4).setText(DataSet.ADDITIONAL[position]);
    }

    @Override
    public int getItemCount() {
        return DataSet.BENE_PERC.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ArrayList<TextView> textView = new ArrayList<>();


        ViewHolder(View itemView) {
            super(itemView);

            textView.add((TextView) itemView.findViewById(R.id.textView11));
            textView.add((TextView) itemView.findViewById(R.id.textView12));
            textView.add((TextView) itemView.findViewById(R.id.textView21));
            textView.add((TextView) itemView.findViewById(R.id.textView22));
            textView.add((TextView) itemView.findViewById(R.id.textView23));

            View.OnClickListener onClickListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, TargetsActivity.class);
                    intent.putExtra("position", getPosition());
                    mContext.startActivity(intent);
                }
            };
            for (TextView tv : textView){
                tv.setOnClickListener(onClickListener);
            }
            itemView.findViewById(R.id.imageButton_investment)
                    .setOnClickListener(onClickListener);

        }

        TextView getTextView(int position) {
            return textView.get(position);
        }
    }
}
